package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author 梦龙
 * @date 2023/12/7 19:56
 */
@Mapper
public interface OrderMapper {

    /**
     * @description:插入订单数据
     * @return: void
     * @author: 梦龙
     * @time: 2023/12/7 20:54
     */
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus},checkout_time = #{check_out_time} where id = #{ordersId}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long ordersId);

    /**
     * @description:查询订单信息，通过订单id
     * @return: com.sky.entity.Orders
     * @author: 梦龙
     * @time: 2023/12/10 16:58
     */
    @Select("select * from orders where id = #{ordersId}")
    Orders getByOrdersId(Long ordersId);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Update("update orders set status = 6 where id = #{id}")
    void cancelOrder(Long id);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);

    Double getSumByMap(Map map);

    Integer getCountByMap(Map map);

    /**
     * @description:统计指定时间区间内的销量排名前十
     * @return: java.util.List<com.sky.dto.GoodsSalesDTO>
     * @author: 梦龙
     * @time: 2023/12/14 0:27
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
